package me.send.data.service.mapper.provider;

import java.util.List;
import java.util.Map;

import me.send.data.service.pojo.ManagerPermission;
import me.send.data.service.pojo.ManagerRole;

public class ManagerProvider {
	@SuppressWarnings("unchecked")
	public String  getManagerPermissionByRoles(Map<String,Object> params){
		List<ManagerRole> roles=(List<ManagerRole>)params.get("roles");
		StringBuffer sb=new StringBuffer();
    	sb.append(" select p.id,p.roleid roleid,p.permission_name permissionName,p.description from manager_permission p where p.roleid in (");
    	for(ManagerRole role:roles){
    		sb.append(""+role.getRoleid()+"");
    		sb.append(",");
    	}
    	sb.append("-1)");
    	return sb.toString();
	}
	@SuppressWarnings("unchecked")
	public String  getManagerPermissionTreeByPermissions(Map<String,Object> params){
		List<ManagerPermission> perssions =(List<ManagerPermission>)params.get("perssions");
		StringBuffer sb=new StringBuffer();
		sb.append(" select * from manager_permission_tree p where p.permissionId in (");
		for(ManagerPermission permission:perssions){
			sb.append(""+permission.getId()+"");
			sb.append(",");
		}
		sb.append("-1)");
		return sb.toString();
	}
	
	@SuppressWarnings("unchecked")
	public String insertManagerPermissionTree(Map<String,Object> params){
		List<Integer> tids =(List<Integer>)params.get("tids");
		Long pid =(Long)params.get("pid");
		StringBuffer sb=new StringBuffer();
		sb.append("insert into manager_permission_tree(treeId,permissionId) values ");
		if(tids.size()<1){
			return "delete from manager_permission_tree  where permissionId="+pid;
		}
		for(int i=0;i<tids.size();i++){
			if(i!=tids.size()-1){
				sb.append("("+Long.valueOf(tids.get(i))+","+pid+")");
				sb.append(",");
			}else{
				sb.append("("+Long.valueOf(tids.get(i))+","+pid+")");
			}
		}
		return sb.toString();
	}
}
